/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __BEZIERCURVE_H__
#define __BEZIERCURVE_H__

#include "../PointsSet.h"
#include "./AbstractCurve.h"

#define CURVE_EPS		0.5f		


class BezierCurve: public PointsSet, AbstractCurve {
protected:
	cWinColor mPolygonColor;
	cBool mIsPolygonVisible;
	cBool mArePointsVisible;

	cBool StopCubic(Point4D& a1, Point4D& b1, Point4D& a2, Point4D& b2);
	cBool StopQuadric(Point4D& a, Point4D& b);
	Point4D CalculateMidPoint(Point4D& a, Point4D& b);

	cVoid RenderPolygon(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color, Point4D *tab, cInt iSize);
	cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, Point4D *tab, cInt iSize);
	cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color, Point4D *tab, cInt iSize);
	cVoid CubicBezier(Renderer& renderer, ProjectionPlane& plane, cWinColor color, 
		Point4D p0, Point4D p1, Point4D p2, Point4D p3);
	cVoid QuadricBezier(Renderer& renderer, ProjectionPlane& plane, cWinColor color,
		Point4D p0, Point4D p1, Point4D p2);
	cVoid RenderPolygon(Renderer& renderer, Matrix4D& mProjectionMatrix, ProjectionPlane& plane,
		cWinColor color);
public:

    /**************************************************************
    * Constructors                                                *
    ***************************************************************/
    BezierCurve();
	BezierCurve(cBool arePointsVisible, cBool isPolygonVisible, cWinColor color);

	/**************************************************************
    * Operators                                                   *
    ***************************************************************/


    /**************************************************************
    * Other helpful functions                                     *
    ***************************************************************/
	cVoid SwitchPolygonVisibility();
	cVoid SwitchPointsVisibility();
	virtual Point4D GetCurvePoint(cInt iIndex);
	virtual cInt GetCurveNrOfPoints();
	virtual cChar* GetName();
	virtual cVoid DisplayInfo(Renderer& renderer);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color);
};                                                                 

#endif // __BEZIERCURVE_H__